# -- coding: utf-8 --

import requests

# #发送get请求需要url, header, 参数
# r = requests.get('http://127.0.0.1:8000/api/get_event_list/?eid=1')
# rep = r.json()
# if rep['message'] == 'success':
#     print('测试成功.')
# else:
#     print('测试失败')

# #发送post请求: url, header, body
# # headers = {}
# # datas = {'eid':'13', 'name':'千锋手机发布会7', 'limit':'34', 'address':'class 4', 'start_time':'2016-09-11 12:00:00'}
# # r = requests.post('http://127.0.0.1:8000/api/add_event/', data=datas, headers = headers)
# # print(r.json())
# # print(r.text)

# s = requests.session()
#
# #登陆
# url = 'http://localhost:8088/smeoa/index.php?m=login&a=check_login'
# # datas = {'emp_no':'admin','password':'admin'}
# headers = {'Content-Type': 'application/x-www-form-urlencoded'}
# datas = 'emp_no=admin&password=admin'
# r = s.post(url, data = datas, headers = headers)
# if '退出' in r.text:
#     print('success')
# else:
#     print('fail')
#
# url = 'http://localhost:8088/smeoa/index.php?m=task&a=folder&fid=all'
# r = s.post(url)
# print(r.text)

# ================JSON================
# import json
#
# str = {"emp_no": "admin", "password":"admin"}
# print(type(str))
# json_str = json.dumps(str)  #把python对象序列化为JSON串
# print(json_str)
# print(type(json_str))
#
# new_str = json.loads(json_str)  #把JSON串转为Python对象
# print(new_str)
# print(type(new_str))

# ============上传=============
# s = requests.session()
#
# #登陆
# url = 'http://localhost:8088/smeoa/index.php?m=login&a=check_login'
# # datas = {'emp_no':'admin','password':'admin'}
# headers = {'Content-Type': 'application/x-www-form-urlencoded'}
# datas = 'emp_no=admin&password=admin'
# r = s.post(url, data = datas, headers = headers)
# if '退出' in r.text:
#     print('success')
# else:
#     print('fail')
#
# url = 'http://localhost:8088/smeoa/index.php?m=task&a=upload'
# file = {'name':open(r'C:\Users\Administrator\Desktop\testDemo.txt', 'rb')}
# r = s.post(url, files = file)
# sid = r.json()['sid']
#
# url = 'http://localhost:8088/smeoa/index.php?m=task&a=save'
# datas = {'add_file':sid, 'opmode':'add','name':'title','expected_time':'2019-06-11 16:10','content':'content'}
# r = s.post(url, data=datas)
# print(r.text)

# #============下载==============
# url ='https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1562061140894&di=fec9d3c3fd658fbae9e34f59c1e79d93&imgtype=0&src=http%3A%2F%2F5b0988e595225.cdn.sohucs.com%2Fimages%2F20170910%2F51ea0fcedd134eff8b7d8384920ffbd2.jpeg'
# r = requests.get(url)
# resp = r.content
# # with open('01.jpg', 'wb') as f:
# #     f.write(resp)
# f = open('01.jpg', 'wb')
# f.write(resp)


# =============重定向================
# 登陆
url = 'http://localhost:8088/smeoa/index.php?m=login&a=check_login'
# datas = {'emp_no':'admin','password':'admin'}
headers = {'Content-Type': 'application/x-www-form-urlencoded'}
datas = 'emp_no=admin&password=admin'
r = requests.post(url, data=datas, headers=headers, allow_redirects=False)
print(r.text)
# if '退出' in r.text:
#     print('success')
# else:
#     print('fail')
